import { ref } from 'vue';

import type { ListState } from '@/types';

import { getSwiperList } from '../api';

const useSwiperList = () => {
  const state = ref<ListState<{ url: string }>>({
    data: [],
    loading: false,
    total: 0,
  });

  const fetchData = async () => {
    try {
      state.value.loading = true;
      const { data } = await getSwiperList();
      state.value.data = data.data;
      state.value.total = data.data?.length || 0;
    } catch (error) {
      //
    } finally {
      state.value.loading = false;
    }
  };

  return {
    state,
    fetchData,
  };
};

export default useSwiperList;
